{include file="public/header" /}
<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">订单管理</a>
        <a>
          <cite>合同文件</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <button class="layui-btn layui-btn-sm" onclick="x_admin_show('上传文件(支持多文件)','{:url(\'index/Order/upOrderFile\',[\'id\'=>$id])}')">上传文件</button>
    <button class="layui-btn-sm layui-btn layui-btn-danger"
    onclick="Clear()">清理失效记录</button>
    <div class="layui-row">
        <div class="container-wrap">
            <div class="box-1">
                <table class="layui-table" style="text-align: center">
                    <tbody>
                        <tr style="background-color:lightgray">
                            <td>序号</td>
                            <td>上传时间</td>
                            <td>上传者</td>
                            <td>预览</td>
                            <td>备注</td>
                            <td>操作</td>
                        </tr>
                    {if !$files||count($files)<=0}
                        <tr>
                            <td colspan="6" style="text-align: center">还没有上传合同文件</td>
                        </tr>
                    {else}
                    {volist name = 'files' id='data' $key}
                        <tr>
                            <td>{$key+1}</td>
                            <td>{$data.create_time}</td>
                            <td>{$data.create_user}</td>
                            <td>
                                {if $data.type =='png'||$data.type =='jpg'}
                                <button class="layui-btn layui-btn-sm" onclick="ifBas('{$data.path}')">预览</button>
                                {/if}
                                {if $data.type =='doc'||$data.type =='docx'}
                                <button class="layui-btn layui-btn-xs">
                                    <a style="color: white" href="{$data.path}" download="{$order_number}.{$data.type}">
                                        <i class="layui-icon">WORD</i>
                                    </a>
                                </button>
                                {/if}
                                {if $data.type =='tif'}
                                <button class="layui-btn layui-btn-xs">
                                    <a style="color: white" href="{$data.path}" download="{$order_number}.{$data.type}">
                                        <i class="layui-icon">TIF</i>
                                    </a>
                                </button>
                                {/if}
                                {if $data.type == 'pdf'}
                                <button class="layui-btn layui-btn-xs"
                                onclick="x_admin_show('合同文件预览','{:url(\'index/Order/previewPdf\',[\'id\'=>$data.id])}')">
                                    <i class="layui-icon">PDF</i>
                                </button>
                                {/if}
                            </td>
                            <td>
                                <input id="name{$key+1}" class="layui-input" type="text" style="min-width: 100px;text-align: center"
                                       value="{$data.describe}" onchange="editName('name{$key+1}',{$data.id})">
                            </td>
                            <td>
                                <button class="layui-btn layui-btn-xs">
                                    <a style="color: white" href="{$data.path}" download="{$order_number}.{$data.type}">
                                        <i class="layui-icon layui-icon-download-circle"></i>
                                    </a>
                                </button>
                                <button class="layui-btn layui-btn-xs layui-btn-danger"
                                onclick="delFiles('{$data.id}')">
                                    <i class="layui-icon layui-icon-delete"></i>
                                </button>
                            </td>
                        </tr>
                    {/volist}
                    {/if}
                    </tbody>
                </table>
            </div>
        </div>
        <div class="page">
            {:$page}
        </div>
    </div>
</div>
<!-- 脚本 -->
<script>
    $(function () {
    })
    function YuLan(url) {
        var html = '<body>'+
            '<div align="center" style="width: 100%">'+
            '<img id="imgY" style="max-width: 100%;height: auto" src="'+url+'"/>'+
            '</div>'+
            '</body>';
        layer.open({
            type: 1,
            skin: 'layui-layer-rim', //加上边框
            area: ['80%', '80%'], //宽高
            skin: 'layui-layer-nobg', //没有背景色
            shadeClose: true,
            content: html
        });
    }
    function YuLans(url) {
        var html = '<body>'+
            '<div align="center" style="max-width:100%">'+
            '<img id="imgY" src="'+url+'"/>'+
            '</div>'+
            '</body>';
        var newwindow = window.open('', "_blank",'');
        newwindow.document.write(html);
    }
    function delFiles(id) {
        layer.confirm('确定删除该记录与文件？', {
            btn: ['确定','取消'] //按钮
        }, function(){
            $.ajax({
                url:'{:url("index/Order/DelFiles")}',
                type:'post',
                dataType:'json',
                data:{
                    id
                },success:function (data) {
                    try{
                        if(data.state == 200){
                            layer.msg(data.msg,{icon:1,time:2000},function () {
                                window.location.reload()
                            });
                            return
                        }
                        if(data.state == 400){
                            layer.msg(data.msg,{icon:0,time:2000});
                            return
                        }
                    }catch (e) {
                        layer.msg('网络错误,稍后再试',{icon:0,time:2000});
                        return
                    }
                },error:function (data) {
                    layer.msg('网络错误稍后再试',{icon:0,time:2000});
                    return;
                }
            })
        }, function(){
            layer.msg('已取消', {
                time: 2000, //2s后自动关闭
            });
            return false;
        });
    }
    function Clear() {
        layer.confirm('确定清除所有失效文件的记录,耗时可能较长？', {
            btn: ['确定','取消'] //按钮
        },function () {
            $.ajax({
                url:'{:url("index/order/DelAllFiles",["order_id"=>$id])}',
                type:'get',
                dataType:'json',
                success:function (data) {
                    try{
                        if(data.state == 200){
                            layer.msg(data.msg,{icon:1,time:2000},function () {
                                window.location.reload()
                            });
                            return
                        }
                        if(data.state == 400){
                            layer.msg(data.msg,{icon:0,time:2000});
                            return
                        }
                    }catch (e) {
                        layer.msg('网络错误,稍后再试',{icon:0,time:2000});
                        return
                    }
                },error:function (data) {
                    layer.msg('网络错误稍后再试',{icon:0,time:2000});
                    return;
                }
            });
        },function () {

        });
    }
    function editName(id,Id) {
        var IdName = '#'+id;
        var name = $(IdName).val().trim()==""?"无":$(IdName).val().trim();
        $.ajax({
            url:'{:url("index/Order/editName")}',
            type:'post',
            data:{
                name,Id
            },error:function () {
                layer.msg('修改失败,稍后再试',function () {
                    window.location.reload();
                    return;
                })
            }
        })
    }
    function ifBas(url) {
        layer.confirm('选择打开方式!', {
            btn: ['弹出层','新窗口'] //按钮
        }, function(){
            YuLan(url);
            layer.msg('ok',{time:1000});
            return false;
        }, function(){
            YuLans(url);
            layer.msg('ok',{time:1000});
            return false;
        });
    }
</script>
</body>